package demo4;
import java.util.ArrayList;
@SuppressWarnings({"all"})
//generic就是泛型的意思
public class Test {
    public static void main(String[] args) {
        ArrayList<Dog> arrayList = new ArrayList<Dog>();
        arrayList.add(new Dog("狗1",3));
        arrayList.add(new Dog("狗2",5));
        arrayList.add(new Dog("狗3",8));
        //arrayList.add(new Cat("猫1",9));
        /*for (Object o : arrayList) {
            Dog dog=(Dog)o;
            System.out.println(dog.getName()+"-"+dog.getAge());
        }*/
        for (Dog dog : arrayList) {
            System.out.println(dog.getName()+"-"+dog.getAge());
        }
    }
}

class Cat{
    private String name;
    private int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
